<template>
   <!--订购节点信息 -->
  <div style="height:520px">
   <!-- table -->
    <FilterTable
      ref="table"
      height='430'
      :columns="columns"
      :isSelectColumn="isSelectColumn"
      :fetchapi="fetchParams"
      :params="flterValue"
      :datakey="'records'"
      :onColumnsChange="columns => this.columns = columns"
    >
      <template slot="controls" v-if="value.type!=='show'">
        <el-button size="small" type="primary" icon="el-icon-plus" @click="addHandle(123,'add')">新增</el-button>
      </template>
    </FilterTable>
  <BaseDialog title="订购节点新增" :visible.sync="visibleAdd"
      width="400px"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}" >
      <addModal  ref="addDialog" @close="closeHandler" />
   </BaseDialog>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import addModal from './infoOrderModal';

export default {
  mixins: [dictionary],
  components: {
    addModal
  },
  props: {
    value: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      visibleAdd:false,
      isSelectColumn: false,
      flterValue: {}, //参数
      columns: this.creatHeader(),
      fetchParams: null //ipa 接口
    };
  },
  mounted() {
    console.log(this.value); //获取到行id 、类型（新增、详情）
    //请求接口进行赋值，自己写吧
  },
  methods: {
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          render: (props, h) => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.addHandle(props.row,'edit')}>
                  编辑
                </el-button>
                <el-divider direction="vertical" />
                <el-button size="mini" type="text" >
                  删除
                </el-button>
              </div>
            );
          }
        },
        { title: '订购节点类型', dataIndex: 'field2', sorter: true ,
           render: props => {    //编码转汉字
            return <span>{this.createDictText(props.row.basedataRelateId, '1611')}</span>;
        }},
        { title: '订购时间', dataIndex: 'field3',dateFormat:'yyyy-MM-dd', sorter: true },
        { title: '到货时间', dataIndex: 'field4',dateFormat:'yyyy-MM-dd', sorter: true},
        { title: '订购金额', dataIndex: 'field5',numberFormat:true,  sorter: true},
        { title: '安装时间', dataIndex: 'field6',dateFormat:'yyyy-MM-dd', sorter: true}
      ];
    },
    addHandle(row,type) {
      //逻辑自己写
      this.initData =  {
        type: 'add',   //add/edit/show
        id:1001    //行id
      };
      this.visibleAdd = true;
    },
    closeHandler(data){
      this.visibleAdd = data.visible;
    }
  }
};
</script>